package com.bodystm.temperature.patient;

import java.util.Collections;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cascade;
import org.springframework.format.annotation.DateTimeFormat;

import com.bodystm.temperature.bed.Bed;
import com.mimosa.common.entity.BaseEntity;
import com.mimosa.common.system.user.TUser;

/**
 * 鐥呬汉淇℃伅
 * 
 * @author ggeagle
 *
 */
@Table(name = "T_Patient")
@Entity
public class Patient extends BaseEntity {
	/**
	 * 姓名
	 */
	private String name;
	/**
	 * 主治医师
	 */
	private String doctor;
	/**
	 * 值班护士
	 */
	private String nurse;
	/**
	 * 年龄
	 */
	private String age;
	/**
	 * 性别姓别
	 */
	private String sex;
	/**
	 * 设备号
	 */
	private String equipNo;
	/**
	 * 住院时间
	 */
	private Date startTime;

	private Date listenStartTime;
	private Date listenEndTime;
	/**
	 * 采样时间
	 */
	@DateTimeFormat(pattern="HH:mm")
	private Date samplingTime;
	private String disease;
	/*
	 * 病案号
	 */
	private String medicalRecordNumber;
//	@Column(nullable = true)
//	private float rangeStart;
//	@Column(nullable = true)
//	private float rangeEnd;
	private float superHighDegree;
	private int lowNY;
	private int highNY;
	// 身份证号
	private String personnelId;
	// 家庭住址
	private String address;
	//
	@ManyToOne(cascade = { javax.persistence.CascadeType.ALL })
	private Bed bed;
	//// // 科室
	@ManyToOne(cascade = { javax.persistence.CascadeType.REFRESH })
	private TUser user;

	public TUser getUser() {
		return user;
	}

	//
	public void setUser(TUser user) {
		this.user = user;
	}

	@Transient
	private String bedIds;
	// 人员
	@SuppressWarnings("unchecked")
	@OneToMany(mappedBy = "patient")
	// @Cascade(value = { org.hibernate.annotations.CascadeType.ALL }), orphanRemoval = true
	private Set<PatientBedUser> bedUserList = Collections.EMPTY_SET;

	/*
	 * 就医类型（比如自费）
	 */
	private String medicalTreatmentType;

	/**
	 * 出院时间
	 */
	private Date endTime;
	/**
	 * 此病人携带的设备最后接收存储数据的时间
	 */
	private Date lastSavTime;
	/**
	 * 记录用户临时修正温度数据时要加上的数（接收温度数据时加上这个数再存储）
	 */
	private float num4Correct=0;
	//报警相关
		/**
		 * 警报类型（0代表正常不报警，1代表低温报警，2代表高温报警，3代表超高温报警）
		 */
		//int warningType=0;
		/**
		 * 是否报警，当温度恢复正常时或者用户点击停止后将其设置回true的状态
		 */
		//boolean warningOrNot=true;

	public Set<PatientBedUser> getBedList() {
		return bedUserList;
	}

	public void setBedList(Set<PatientBedUser> bedList) {
		this.bedUserList = bedList;
	}

	public String getBedIds() {
		if (StringUtils.isBlank(bedIds)) {
			StringBuilder bedIds = new StringBuilder();
			for (PatientBedUser t : this.getBedList()) {
				if (bedIds.length() > 0) {
					bedIds.append(",");
				}
				bedIds.append(t.getBed().getId());
			}
			return bedIds.toString();
		} else {
			return bedIds;
		}
	}

	public void setBedIds(String bedIds) {
		this.bedIds = bedIds;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getEquipNo() {
		return equipNo;
	}

	public void setEquipNo(String equipNo) {
		this.equipNo = equipNo;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getDoctor() {
		return doctor;
	}

	public void setDoctor(String doctor) {
		this.doctor = doctor;
	}

	public String getNurse() {
		return nurse;
	}

	public void setNurse(String nurse) {
		this.nurse = nurse;
	}

	public Date getListenStartTime() {
		return listenStartTime;
	}

	public void setListenStartTime(Date listenStartTime) {
		this.listenStartTime = listenStartTime;
	}

	public Date getListenEndTime() {
		return listenEndTime;
	}

	public void setListenEndTime(Date listenEndTime) {
		this.listenEndTime = listenEndTime;
	}

	public String getDisease() {
		return disease;
	}

	public void setDisease(String disease) {
		this.disease = disease;
	}

	public String getMedicalRecordNumber() {
		return medicalRecordNumber;
	}

	public void setMedicalRecordNumber(String medicalRecordNumber) {
		this.medicalRecordNumber = medicalRecordNumber;
	}

	/*public float getRangeStart() {
		return rangeStart;
	}

	public void setRangeStart(float rangeStart) {
		this.rangeStart = rangeStart;
	}

	public float getRangeEnd() {
		return rangeEnd;
	}

	public void setRangeEnd(float rangeEnd) {
		this.rangeEnd = rangeEnd;
	}*/

	public Date getSamplingTime() {
		return samplingTime;
	}

	public void setSamplingTime(Date samplingTime) {
		this.samplingTime = samplingTime;
	}

	public int getLowNY() {
		return lowNY;
	}

	public void setLowNY(int lowNY) {
		this.lowNY = lowNY;
	}

	public int getHighNY() {
		return highNY;
	}

	public void setHighNY(int highNY) {
		this.highNY = highNY;
	}

	public float getSuperHighDegree() {
		return superHighDegree;
	}

	public void setSuperHighDegree(float superHighDegree) {
		this.superHighDegree = superHighDegree;
	}

	public String getPersonnelId() {
		return personnelId;
	}

	public void setPersonnelId(String personnelId) {
		this.personnelId = personnelId;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getMedicalTreatmentType() {
		return medicalTreatmentType;
	}

	public void setMedicalTreatmentType(String medicalTreatmentType) {
		this.medicalTreatmentType = medicalTreatmentType;
	}

	public Bed getBed() {
		return bed;
	}

	public void setBed(Bed bed) {
		this.bed = bed;
	}

	public Date getLastSavTime() {
		return lastSavTime;
	}

	public void setLastSavTime(Date lastSavTime) {
		this.lastSavTime = lastSavTime;
	}

	public float getNum4Correct() {
		return num4Correct;
	}

	public void setNum4Correct(float num4Correct) {
		this.num4Correct = num4Correct;
	}
}